#pragma once
#include <iostream>
#include <time.h>
#include <string>
#include <vector>
using namespace std;

class Cookie
{
public:
    Cookie()
    {
        _setcookie = "login=";
    }
    void Create(string &username, string& password, int addt)
    {
        _setcookie+=Getuser(username,password);
        _setcookie+="expires=" + Getexpires(addt) + ";";    
        _setcookie+="path=/";
    }
    string Getuser(string& username,string& password)
    {   
        return "username=" + username + "password=" + password + ";";
    }

    string Getexpires(int addt)
    {
        time_t now = time(nullptr) + addt;
        struct tm *lt = gmtime(&now);
        char buffer[1024];
        snprintf(buffer, sizeof(buffer), "expires=%s, %02d %s %d %02d:%02d:%02d UTC",
                 Getweekday(lt->tm_wday).c_str(),
                 lt->tm_mday,
                 Getyrear(lt->tm_mon).c_str(), 
                 lt->tm_year + 1900,
                 lt->tm_hour,
                 lt->tm_min,
                 lt->tm_sec);
        return buffer;
    }

    string Getyrear(int month)
    {
        vector<string> getmonth{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
        return getmonth[month];
    }
    string Getweekday(int weekday)
    {
        vector<string> getweekday{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
        return getweekday[weekday];
    }
    string Getcookie()
    {
        return _setcookie;
    }
private:
    string _setcookie;
};
